package com.eyeem.recyclerviewtools.sample.adapter;/**
 * Created by admin on 2016/8/11.
 */

import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import com.eyeem.recyclerviewtools.adapter.AbstractSectionAdapter;
import com.eyeem.recyclerviewtools.adapter.WrapAdapter;
import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersAdapter;

/**
 * 项目名称：
 * 类名称：
 * 类描述：
 * 创建人：
 * 创建时间：
 * 修改人：
 * 修改时间：
 * 修改备注：
 *
 * @version V1.0
 */
public class StickyWrapAdapter extends WrapAdapter implements StickyRecyclerHeadersAdapter {

    //AnimalsAdapter wrappedAdapter;
    StickyRecyclerHeadersAdapter mStickyRecyclerHeadersAdapter;

    public StickyWrapAdapter(RecyclerView.Adapter wrappedAdapter) {
        super(wrappedAdapter);
        if (!(wrappedAdapter instanceof AnimalsAdapter)) {
            throw new IllegalStateException("wrappedAdapter " +
                    " must extend " + AnimalsAdapter.class.getSimpleName());
        }
        if (!(wrappedAdapter instanceof StickyRecyclerHeadersAdapter)) {
            throw new IllegalStateException("wrappedAdapter " +
                    " must implement " + AnimalsAdapter.class.getSimpleName());
        }

        this.mStickyRecyclerHeadersAdapter = (StickyRecyclerHeadersAdapter) wrappedAdapter;

    }

    /**
     * @param wrappedAdapter wrappedAdapter
     * @param sectionAdapter sectionAdapter
     * @deprecated
     */
    public StickyWrapAdapter(RecyclerView.Adapter wrappedAdapter, AbstractSectionAdapter sectionAdapter) {
        super(wrappedAdapter, sectionAdapter);
        if (!(wrappedAdapter instanceof AnimalsAdapter)) {
            throw new IllegalStateException("wrappedAdapter " +
                    " must implement " + AnimalsAdapter.class.getSimpleName());
        }
    }

    @Override
    public long getHeaderId(int position) {
        return this.mStickyRecyclerHeadersAdapter.getHeaderId(position);
    }

    @Override
    public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
        return this.mStickyRecyclerHeadersAdapter.onCreateHeaderViewHolder(parent);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder, int position) {
        mStickyRecyclerHeadersAdapter.onBindHeaderViewHolder(holder, position);
    }
}
